--------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  c:\dataverse_files\Election_26AUG2017_Stata.log
  log type:  text
 opened on:  10 Mar 2018, 10:03:31

. use USelec_SenateRepre_final,clear

. 
. gen proprep_h=oppositions_h/totalseathouse

. gen proprep_s=oppositions_s/totalseatsenate

. gen s1_demo=propdemo_h-0.5

. gen s2_demo=propdemo_s-0.5

. gen delta1_demo=s1_demo>=0 

. gen delta2_demo=s2_demo>=0 

. gen delta_demo=(delta1_demo*delta2_demo)

. gen s1_rep=proprep_h-0.5 

. gen s2_rep=proprep_s-0.5

. gen delta1_rep=s1_rep>=0

. gen delta2_rep=s2_rep>=0

. gen delta_rep=(delta1_rep*delta2_rep)

. gen t=congress

. 
. 
. ** we use s=proportion of Rep in each house
. gen d=delta_rep

. gen d1=delta1_rep

. gen d2=delta2_rep

. gen irr=(delta1_rep==0)*(delta2_rep==0)*(delta_demo==0)

. ** irr=1 if none of parties dominant
. gen sen_rep=1-irr

. 
. 
. 
. * ========Choose Dependent Variable
. ** mf is chosen by Cross-Validation for each neighbor. And it can be obtained with another GAUSS program
. ****======== Y=LPI ========
. quietly sum lpi

. gen y_l=(lpi-r(mean))/r(sd)

. scalar mf_l_sq=1.4

. scalar mf_l_sq1=1.1

. scalar mf_l_sq2=1.8

. scalar mf_l_ov=1.8

. scalar mf_l_ov1=1.5

. scalar mf_l_ov2=1.9

. 
. ****======== Y=MLI ========
. quietly sum mli

. gen y_m=(mli-r(mean))/r(sd)

. scalar mf_m_sq=1.4

. scalar mf_m_sq1=2.3

. scalar mf_m_sq2=1.4

. scalar mf_m_ov=1.6

. scalar mf_m_ov1=1.5

. scalar mf_m_ov2=1.9

. 
. keep if sen_rep==1
(4 observations deleted)

. ** remove the cases that none of parties is the majoritiy
. 
. 
. quietly sum s1_rep

. scalar sd1=r(sd) 

. gen s1=(s1_rep-r(mean))/r(sd)

. *normalizing s1
. quietly sum s2_rep

. scalar sd2=r(sd) 

. gen s2=(s2_rep-r(mean))/r(sd)

. *normalizing s2
. matrix define sd=(sd1\sd2) 

. quietly correlate s1 s2 

. scalar rho=r(rho) 

. scalar n=r(N)

. scalar k=2 

. ** k is a number of running variables
. scalar h0=n^(-1/(k+4))

. ** RoT bandwidth should be SD(S)*h0, and our sd(s1)=sd(s2)=1 by normalizing
. scalar neva=5

. 
. 
. 
. ***********************************************************
. ********** Square neighbor h RoT **************************
. scalar h1=h0

. scalar h2=h0

. **q is local sample selector 
. gen q1=(s1<0)*(s1>=-h1)+(s1>=0)*(s1<=h1) 

. gen q2=(s2<0)*(s2>=-h2)+(s2>=0)*(s2<=h2)

. gen q_srt=q1*q2

. ** local sample for srt
. 
. 
. ** LSE's with linear E(Y0|S) in (3.10)
. local x1 "d d1 d2 s1 s2 t"

. quietly regress y_l `x1' if q_srt==1, r

. estimates store y_l_1_srt

. quietly regress y_m `x1' if q_srt==1, r

. estimates store y_m_1_srt

. 
. 
. ** Two min-score approaches 
. gen sm=(s1>s2)*s2+(s1<s2)*s1

. quietly sum sm

. scalar sdm=r(sd)

. scalar hm=sdm*h0

. gen qm=(sm<0)*(sm>=-hm)+(sm>=0)*(sm<=hm)

. local xm "d sm t"        

. quietly regress y_l `xm' if qm==1, r

. estimates store y_l_m_srt

. quietly regress y_m `xm' if qm==1, r

. estimates store y_m_m_srt

. 
. 
. ** One-dimensional localizations 
. gen a1=d2*q1

. local x11 "d s1 s2 t"

. quietly regress y_l `x11' if a1==1, r

. estimates store y_l_11_srt

. quietly regress y_m `x11' if a1==1, r

. estimates store y_m_11_srt

. 
. gen a2=d1*q2

. local x12 "d s1 s2 t"

. quietly regress y_l `x12' if a2==1, r

. estimates store y_l_12_srt

. quietly regress y_m `x12' if a2==1, r

. estimates store y_m_12_srt

. 
. *estimates table y_l_1_srt y_l_m_srt y_l_11_srt y_l_12_srt, t keep(d)
. *estimates table y_m_1_srt y_m_m_srt y_m_11_srt y_m_12_srt, t keep(d)
. 
. drop q1 q2 qm a1 a2

. 
. 
. 
. **********************************************************************
. ********** Square neighbor with single h CV **************************
. scalar h1_l=mf_l_sq*h0

. scalar h2_l=mf_l_sq*h0

. scalar h1_m=mf_m_sq*h0

. scalar h2_m=mf_m_sq*h0

. gen q1_l=(s1<0)*(s1>=-h1_l)+(s1>=0)*(s1<=h1_l) 

. gen q2_l=(s2<0)*(s2>=-h2_l)+(s2>=0)*(s2<=h2_l) 

. gen q1_m=(s1<0)*(s1>=-h1_m)+(s1>=0)*(s1<=h1_m) 

. gen q2_m=(s2<0)*(s2>=-h2_m)+(s2>=0)*(s2<=h2_m) 

. gen q_l_scv=q1_l*q2_l

. gen q_m_scv=q1_m*q2_m

. 
. ** LSE's with linear E(Y0|S) in (3.10)
. quietly regress y_l `x1' if q_l_scv==1, r

. estimates store y_l_1_scv

. quietly regress y_m `x1' if q_m_scv==1, r

. estimates store y_m_1_scv

. 
. ** Two min-score approaches 
. scalar hm_l=mf_l_sq*sdm*h0

. scalar hm_m=mf_m_sq*sdm*h0

. gen qm_l=(sm<0)*(sm>=-hm_l)+(sm>=0)*(sm<=hm_l)

. gen qm_m=(sm<0)*(sm>=-hm_m)+(sm>=0)*(sm<=hm_m)

. quietly regress y_l `xm' if qm_l==1, r

. estimates store y_l_m_scv

. quietly regress y_m `xm' if qm_m==1, r

. estimates store y_m_m_scv

. 
. 
. ** One-dimensional localizations 
. gen a1_l=d2*q1_l

. gen a1_m=d2*q1_m

. quietly regress y_l `x11' if a1_l==1, r

. estimates store y_l_11_scv

. quietly regress y_m `x11' if a1_m==1, r

. estimates store y_m_11_scv

. 
. gen a2_l=d1*q2_l

. gen a2_m=d1*q2_m

. quietly regress y_l `x12' if a2_l==1, r

. estimates store y_l_12_scv

. quietly regress y_m `x12' if a2_m==1, r

. estimates store y_m_12_scv

. 
. 
. ** Boundary-weighting estimator 
. gen l=y_l

. gen m=y_m

. foreach v of varlist l m {
  2. scalar e1lo=h1_`v'
  3. scalar e1hi=((1.75-h1_`v')>h1_`v')*(1.75-h1_`v')+((1.75-h1_`v')<h1_`v')*(h1_`v')
  4. scalar e1inc=(e1hi-e1lo)/neva
  5. 
. scalar e2lo=h2_`v'
  6. scalar e2hi=((1.75-h2_`v')>h2_`v')*(1.75-h2_`v')+((1.75-h2_`v')<h2_l)*(h2_`v')
  7. scalar e2inc=(e2hi-e2lo)/neva
  8. 
. 
. gen eva1=e1lo
  9. gen eva2=e2lo
 10. matrix define blse1c=(0\0\0\0\0)
 11. matrix define blse2c=(0\0\0\0\0)
 12. matrix define den1=(0\0\0\0\0)
 13. matrix define den2=(0\0\0\0\0)
 14. 
. forvalues i=1/5{
 15. 
.   ** cutoff shifts for s1 only; then do ols; no partial effect 
.   gen s1c=s1-eva1
 16.   gen q1c=(s1c<0)*(s1c>=-h1_`v')+(s1c>=0)*(s1c<=h1_`v')
 17.   gen a1c=q1c*q2_`v'
 18.   local x1c "d s1c s2 t"
 19.   quietly regress `v' `x1c' if a1c==1, r
 20.   matrix blse1c[`i',1]=_b[d]
 21.   gen ker1=normalden(s1c/h1_`v')*normalden(s2/h2_`v')
 22.   quietly sum ker1
 23.   matrix den1[`i',1]=r(mean)/(h1_`v'*h2_`v')
 24.   quietly replace eva1=eva1+e1inc
 25.  
.   gen s2c=s2-eva2
 26.   gen q2c=(s2c<0)*(s2c>=-h2_`v')+(s2c>=0)*(s2c<=h2_`v')
 27.   gen a2c=q2c*q1_`v'
 28.   local x2c "d s2c s1 t"
 29.   quietly regress `v' `x2c' if a2c==1, r
 30.   matrix blse2c[`i',1]=_b[d]
 31.   gen ker2=normalden(s2c/h2_`v')*normalden(s1/h1_`v')
 32.   quietly sum ker2
 33.   matrix den2[`i',1]=r(mean)/(h1_`v'*h2_`v')
 34.   quietly replace eva2=eva2+e2inc 
 35.   drop s1c q1c a1c ker1 s2c q2c a2c ker2 
 36.  
. }
 37. drop eva1 eva2  
 38. matrix temp1=den1+den2
 39. scalar sumden=temp1[1,1]+temp1[2,1]+temp1[3,1]+temp1[4,1]+temp1[5,1]
 40. matrix bwei0=(den1'*blse1c+den2'*blse2c)/sumden
 41. scalar bwei_`v'_scv=bwei0[1,1]
 42. }

. 
. *estimates table y_l_1_scv y_l_m_scv y_l_11_scv y_l_12_scv, t keep(d)
. *estimates table y_m_1_scv y_m_m_scv y_m_11_scv y_m_12_scv, t keep(d)
. *disp bwei_l_scv  bwei_m_scv
. ** CI of bwei is calculated with bootstrap
. 
. drop q1_l q2_l q1_m q2_m qm_l qm_m a1_l a1_m a2_l a2_m

. 
. 
. 
. 
. **********************************************************************
. ********** Square neighbor with two h CV **************************
. scalar h1_l=mf_l_sq1*h0

. scalar h2_l=mf_l_sq2*h0

. scalar h1_m=mf_m_sq1*h0

. scalar h2_m=mf_m_sq2*h0

. gen q1_l=(s1<0)*(s1>=-h1_l)+(s1>=0)*(s1<=h1_l) 

. gen q2_l=(s2<0)*(s2>=-h2_l)+(s2>=0)*(s2<=h2_l) 

. gen q1_m=(s1<0)*(s1>=-h1_m)+(s1>=0)*(s1<=h1_m) 

. gen q2_m=(s2<0)*(s2>=-h2_m)+(s2>=0)*(s2<=h2_m) 

. gen q_l_scv2=q1_l*q2_l

. gen q_m_scv2=q1_m*q2_m

. 
. ** LSE's with linear E(Y0|S) in (3.10)
. quietly regress y_l `x1' if q_l_scv2==1, r

. estimates store y_l_1_scv2

. quietly regress y_m `x1' if q_m_scv2==1, r

. estimates store y_m_1_scv2

. 
. ** Two min-score approaches 
. scalar mf_l_sm=(mf_l_sq1<mf_l_sq2)*mf_l_sq1+(mf_l_sq1>mf_l_sq2)*mf_l_sq2

. scalar mf_m_sm=(mf_m_sq1<mf_m_sq2)*mf_m_sq1+(mf_m_sq1>mf_m_sq2)*mf_m_sq2

. scalar hm_l=mf_l_sm*sdm*h0

. scalar hm_m=mf_m_sm*sdm*h0

. gen qm_l=(sm<0)*(sm>=-hm_l)+(sm>=0)*(sm<=hm_l)

. gen qm_m=(sm<0)*(sm>=-hm_m)+(sm>=0)*(sm<=hm_m)

. quietly regress y_l `xm' if qm_l==1, r

. estimates store y_l_m_scv2

. quietly regress y_m `xm' if qm_m==1, r

. estimates store y_m_m_scv2

. 
. 
. ** One-dimensional localizations 
. gen a1_l=d2*q1_l

. gen a1_m=d2*q1_m

. quietly regress y_l `x11' if a1_l==1, r

. estimates store y_l_11_scv2

. quietly regress y_m `x11' if a1_m==1, r

. estimates store y_m_11_scv2

. 
. gen a2_l=d1*q2_l

. gen a2_m=d1*q2_m

. quietly regress y_l `x12' if a2_l==1, r

. estimates store y_l_12_scv2

. quietly regress y_m `x12' if a2_m==1, r

. estimates store y_m_12_scv2

. 
. 
. ** Boundary-weighting estimator 
. foreach v of varlist l m {
  2. scalar e1lo=h1_`v'
  3. scalar e1hi=((1.75-h1_`v')>h1_`v')*(1.75-h1_`v')+((1.75-h1_`v')<h1_`v')*(h1_`v')
  4. scalar e1inc=(e1hi-e1lo)/neva
  5. 
. scalar e2lo=h2_`v'
  6. scalar e2hi=((1.75-h2_`v')>h2_`v')*(1.75-h2_`v')+((1.75-h2_`v')<h2_l)*(h2_`v')
  7. scalar e2inc=(e2hi-e2lo)/neva
  8. 
. 
. gen eva1=e1lo
  9. gen eva2=e2lo
 10. matrix define blse1c=(0\0\0\0\0)
 11. matrix define blse2c=(0\0\0\0\0)
 12. matrix define den1=(0\0\0\0\0)
 13. matrix define den2=(0\0\0\0\0)
 14. 
. forvalues i=1/5{
 15. 
.   ** cutoff shifts for s1 only; then do ols; no partial effect 
.   gen s1c=s1-eva1
 16.   gen q1c=(s1c<0)*(s1c>=-h1_`v')+(s1c>=0)*(s1c<=h1_`v')
 17.   gen a1c=q1c*q2_`v'
 18.   local x1c "d s1c s2 t"
 19.   quietly regress `v' `x1c' if a1c==1, r
 20.   matrix blse1c[`i',1]=_b[d]
 21.   gen ker1=normalden(s1c/h1_`v')*normalden(s2/h2_`v')
 22.   quietly sum ker1
 23.   matrix den1[`i',1]=r(mean)/(h1_`v'*h2_`v')
 24.   quietly replace eva1=eva1+e1inc
 25.  
.   gen s2c=s2-eva2
 26.   gen q2c=(s2c<0)*(s2c>=-h2_`v')+(s2c>=0)*(s2c<=h2_`v')
 27.   gen a2c=q2c*q1_`v'
 28.   local x2c "d s2c s1 t"
 29.   quietly regress `v' `x2c' if a2c==1, r
 30.   matrix blse2c[`i',1]=_b[d]
 31.   gen ker2=normalden(s2c/h2_`v')*normalden(s1/h1_`v')
 32.   quietly sum ker2
 33.   matrix den2[`i',1]=r(mean)/(h1_`v'*h2_`v')
 34.   quietly replace eva2=eva2+e2inc 
 35.   drop s1c q1c a1c ker1 s2c q2c a2c ker2 
 36.  
. }
 37. drop eva1 eva2  
 38. matrix temp1=den1+den2
 39. scalar sumden=temp1[1,1]+temp1[2,1]+temp1[3,1]+temp1[4,1]+temp1[5,1]
 40. matrix bwei0=(den1'*blse1c+den2'*blse2c)/sumden
 41. scalar bwei_`v'_scv2=bwei0[1,1]
 42. }

. 
. 
. *estimates table y_l_1_scv2 y_l_m_scv2 y_l_11_scv2 y_l_12_scv2, t keep(d)
. *estimates table y_m_1_scv2 y_m_m_scv2 y_m_11_scv2 y_m_12_scv2, t keep(d)
. *disp bwei_l_scv2  bwei_m_scv2
. ** CI of bwei2 is calculated by bootstrap
. 
. drop qm_l qm_m a1_l a1_m a2_l a2_m

. 
. 
. 
. 
. 
. 
. ***********************************************************
. ********** Oval neighbor h RoT **************************
. scalar h1=h0

. scalar h2=h0

. **q is local sample selector 
. gen q_ort=( ((s1/h1)^2)+((s2/h2)^2)-2*rho*(s1/h1)*(s2/h2) )<1

. ** local sample for oval
. 
. 
. ** LSE's with linear E(Y0|S) in (3.10)
. quietly regress y_l `x1' if q_ort==1, r

. estimates store y_l_1_ort

. quietly regress y_m `x1' if q_ort==1, r

. estimates store y_m_1_ort

. 
. *estimates table y_l_1_ort, t keep(d)
. *estimates table y_m_1_ort, t keep(d)
. 
. 
. 
. 
. ********************************************************************
. ********** Oval neighbor with single h CV **************************
. scalar h1_l=mf_l_ov*h0

. scalar h2_l=mf_l_ov*h0

. scalar h1_m=mf_m_ov*h0

. scalar h2_m=mf_m_ov*h0

. gen q_l_ocv=( ((s1/h1_l)^2)+((s2/h2_l)^2)-2*rho*(s1/h1_l)*(s2/h2_l) )<=1

. gen q_m_ocv=( ((s1/h1_m)^2)+((s2/h2_m)^2)-2*rho*(s1/h1_m)*(s2/h2_m) )<=1

. 
. 
. ** LSE's with linear E(Y0|S) in (3.10)
. quietly regress y_l `x1' if q_l_ocv==1, r

. estimates store y_l_1_ocv

. quietly regress y_m `x1' if q_m_ocv==1, r

. estimates store y_m_1_ocv

. 
. 
. 
. ** Boundary-weighting estimator 
. foreach v of varlist l m {
  2. scalar e1lo=h1_`v'
  3. scalar e1hi=((1.75-h1_`v')>h1_`v')*(1.75-h1_`v')+((1.75-h1_`v')<h1_`v')*(h1_`v')
  4. scalar e1inc=(e1hi-e1lo)/neva
  5. 
. scalar e2lo=h2_`v'
  6. scalar e2hi=((1.75-h2_`v')>h2_`v')*(1.75-h2_`v')+((1.75-h2_`v')<h2_`v')*(h2_`v')
  7. scalar e2inc=(e2hi-e2lo)/neva
  8. 
. 
. gen eva1=e1lo
  9. gen eva2=e2lo
 10. matrix define blse1c=(0\0\0\0\0)
 11. matrix define blse2c=(0\0\0\0\0)
 12. matrix define den1=(0\0\0\0\0)
 13. matrix define den2=(0\0\0\0\0)
 14. 
. forvalues i=1/5{
 15. 
.   ** cutoff shifts for s1 only; then do ols; no partial effect 
.   gen s1c=s1-eva1
 16.   quietly sum s1c
 17.   scalar sd1c=r(sd)
 18.   gen q1c=( ((s1c/(sd1c*h1_`v'))^2)+((s2/h2_`v')^2)-2*rho*(s1c/(sd1c*h1_`v'))*(s2/h2_`v') )<=1
 19.   gen a1c=q1c*q2_`v'
 20.   local x1c "d s1c s2 t"
 21.   quietly regress `v' `x1c' if a1c==1, r
 22.   matrix blse1c[`i',1]=_b[d]
 23.   gen ker1=normalden(s1c/h1_`v')*normalden(s2/h2_`v')
 24.   quietly sum ker1
 25.   matrix den1[`i',1]=r(mean)/(h1_`v'*h2_`v')
 26.   quietly replace eva1=eva1+e1inc
 27.  
.   gen s2c=s2-eva2
 28.   quietly sum s2c
 29.   scalar sd2c=r(sd) 
 30.   gen q2c=( ((s2c/(sd2c*h2_`v'))^2)+((s1/h1_`v')^2)-2*rho*(s2c/(sd2c*h2_`v'))*(s1/h1_`v') )<=1
 31.   gen a2c=q2c*q1_`v'
 32.   local x2c "d s2c s1 t"
 33.   quietly regress `v' `x2c' if a2c==1, r
 34.   matrix blse2c[`i',1]=_b[d]
 35.   gen ker2=normalden(s2c/h2_`v')*normalden(s1/h1_`v')
 36.   quietly sum ker2
 37.   matrix den2[`i',1]=r(mean)/(h1_`v'*h2_`v')
 38.   quietly replace eva2=eva2+e2inc 
 39.   drop s1c q1c a1c ker1 s2c q2c a2c ker2 
 40.  
. }
 41. drop eva1 eva2  
 42. matrix temp1=den1+den2
 43. scalar sumden=temp1[1,1]+temp1[2,1]+temp1[3,1]+temp1[4,1]+temp1[5,1]
 44. matrix bwei0=(den1'*blse1c+den2'*blse2c)/sumden
 45. scalar bwei_`v'_ocv=bwei0[1,1]
 46. }

. 
. *estimates table y_l_1_ocv , t keep(d)
. *estimates table y_m_1_ocv , t keep(d)
. *disp bwei_l_ocv  bwei_m_ocv
. ** CI of bwei is calculated by bootstrap
. 
. 
. 
. 
. 
. **********************************************************************
. ********** Oval neighbor with two h CV **************************
. scalar h1_l=mf_l_ov1*h0

. scalar h2_l=mf_l_ov2*h0

. scalar h1_m=mf_m_ov1*h0

. scalar h2_m=mf_m_ov2*h0

. gen q_l_ocv2=( ((s1/h1_l)^2)+((s2/h2_l)^2)-2*rho*(s1/h1_l)*(s2/h2_l) )<=1

. gen q_m_ocv2=( ((s1/h1_m)^2)+((s2/h2_m)^2)-2*rho*(s1/h1_m)*(s2/h2_m) )<=1

. 
. 
. ** LSE's with linear E(Y0|S) in (3.10)
. quietly regress y_l `x1' if q_l_ocv2==1, r

. estimates store y_l_1_ocv2

. quietly regress y_m `x1' if q_m_ocv2==1, r

. estimates store y_m_1_ocv2

. 
. 
. 
. ** Boundary-weighting estimator 
. foreach v of varlist l m {
  2. scalar e1lo=h1_`v'
  3. scalar e1hi=((1.75-h1_`v')>h1_`v')*(1.75-h1_`v')+((1.75-h1_`v')<h1_`v')*(h1_`v')
  4. scalar e1inc=(e1hi-e1lo)/neva
  5. 
. scalar e2lo=h2_`v'
  6. scalar e2hi=((1.75-h2_`v')>h2_`v')*(1.75-h2_`v')+((1.75-h2_`v')<h2_l)*(h2_`v')
  7. scalar e2inc=(e2hi-e2lo)/neva
  8. 
. 
. gen eva1=e1lo
  9. gen eva2=e2lo
 10. matrix define blse1c=(0\0\0\0\0)
 11. matrix define blse2c=(0\0\0\0\0)
 12. matrix define den1=(0\0\0\0\0)
 13. matrix define den2=(0\0\0\0\0)
 14. 
. forvalues i=1/5{
 15. 
.   ** cutoff shifts for s1 only; then do ols; no partial effect 
.   gen s1c=s1-eva1
 16.   quietly sum s1c
 17.   scalar sd1c=r(sd)
 18.   gen q1c=( ((s1c/(sd1c*h1_`v'))^2)+((s2/h2_`v')^2)-2*rho*(s1c/(sd1c*h1_`v'))*(s2/h2_`v') )<=1
 19.   gen a1c=q1c*q2_`v'
 20.   local x1c "d s1c s2 t"
 21.   quietly regress `v' `x1c' if a1c==1, r
 22.   matrix blse1c[`i',1]=_b[d]
 23.   gen ker1=normalden(s1c/h1_`v')*normalden(s2/h2_`v')
 24.   quietly sum ker1
 25.   matrix den1[`i',1]=r(mean)/(h1_`v'*h2_`v')
 26.   quietly replace eva1=eva1+e1inc
 27.  
.   gen s2c=s2-eva2
 28.   quietly sum s2c
 29.   scalar sd2c=r(sd) 
 30.   gen q2c=( ((s2c/(sd2c*h2_`v'))^2)+((s1/h1_`v')^2)-2*rho*(s2c/(sd2c*h2_`v'))*(s1/h1_`v') )<=1
 31.   gen a2c=q2c*q1_`v'
 32.   local x2c "d s2c s1 t"
 33.   quietly regress `v' `x2c' if a2c==1, r
 34.   matrix blse2c[`i',1]=_b[d]
 35.   gen ker2=normalden(s2c/h2_`v')*normalden(s1/h1_`v')
 36.   quietly sum ker2
 37.   matrix den2[`i',1]=r(mean)/(h1_`v'*h2_`v')
 38.   quietly replace eva2=eva2+e2inc 
 39.   drop s1c q1c a1c ker1 s2c q2c a2c ker2 
 40.  
. }
 41. drop eva1 eva2  
 42. matrix temp1=den1+den2
 43. scalar sumden=temp1[1,1]+temp1[2,1]+temp1[3,1]+temp1[4,1]+temp1[5,1]
 44. matrix bwei0=(den1'*blse1c+den2'*blse2c)/sumden
 45. scalar bwei_`v'_ocv2=bwei0[1,1]
 46. }

. 
. 
. *estimates table y_l_1_ocv2 , t keep(d)
. *estimates table y_m_1_ocv2 , t keep(d)
. *disp bwei_l_ocv2  bwei_m_ocv2
. ** CI of bwei2 is calculated by bootstrap
. 
. 
. 
. 
. 
. ***********************************************************
. ************************ Table 1 **************************
. sum proprep_h proprep_s d lpi mli if sen_rep==1

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   proprep_h |       104    .4977889    .1389475   .2022988   .8602151
   proprep_s |       104    .5167611    .1468043   .1666667   .9166667
           d |       104    .4038462    .4930435          0          1
         lpi |       104    90.84423    57.72228        3.9      186.6
         mli |       104    11.11635    5.196453        3.1       20.3

. sum proprep_h proprep_s d lpi mli if s1_rep>=-0.05 & s1_rep<=0.05 & s2_rep>=-0.05 & s2_rep<=0.05 & sen_rep==1

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   proprep_h |        14     .496658    .0282595   .4574713   .5471264
   proprep_s |        14    .5016714    .0191601   .4666667   .5416667
           d |        14    .3571429    .4972452          0          1
         lpi |        14    107.7071    50.84599        4.2      166.1
         mli |        14    12.08571    4.606493        3.1       17.9

. sum proprep_h proprep_s d lpi mli if s1_rep>=-0.1 & s1_rep<=0.1 & s2_rep>=-0.1 & s2_rep<=0.1 & sen_rep==1

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   proprep_h |        42    .4940894     .057377   .4045977   .5958334
   proprep_s |        42    .5036926    .0481697   .4166667   .5888889
           d |        42    .4047619    .4967958          0          1
         lpi |        42    98.50476    55.45094        3.9      178.8
         mli |        42    11.67619    5.242314        3.1       19.7

. 
. 
. 
. 
. 
. ***********************************************************
. ************************  Figure 2 *************************
. twoway (line lpi congress,sort lcolor(navy)), xlabel(0(20)120) ylabel(0(50)225) 

. graph save lpi, replace
(note: file lpi.gph not found)
(file lpi.gph saved)

. twoway (line mli congress,sort lcolor(red)), xlabel(0(20)120) ylabel(0(5)25)

. graph save mli, replace
(note: file mli.gph not found)
(file mli.gph saved)

. graph combine lpi.gph mli.gph, xcommon imargin(vsmall) xsize(11) ysize(5) graphregion(margin(small)) 

. graph save Figure2,replace
(note: file Figure2.gph not found)
(file Figure2.gph saved)

. 
. 
. 
. 
. ***********************************************************
. ************************  Figure 3 *************************
. twoway (scatter s2_rep s1_rep, msymbol(smcircle_hollow)) (scatter s2_rep s1_rep if q_l_scv==1, msymbol(smcircle)), ytitle(, size(small)) ylabel(-0.5(0.1)0.5
> , labsize(small)) ymtick(, labsize(small)) xtitle(, size(small)) xlabel(-0.5(0.1)0.5, labsize(small)) xmtick(, labsize(small)) title(Square Neighbor h CV, s
> ize(small) margin(small)) legend(size(small) margin(zero) region(margin(tiny)) bmargin(small))

. graph save  scv, replace
(note: file scv.gph not found)
(file scv.gph saved)

. 
. twoway (scatter s2_rep s1_rep, msymbol(smcircle_hollow)) (scatter s2_rep s1_rep if q_l_scv2==1, msymbol(smcircle)), ytitle(, size(small)) ylabel(-0.5(0.1)0.
> 5, labsize(small)) ymtick(, labsize(small)) xtitle(, size(small)) xlabel(-0.5(0.1)0.5, labsize(small)) xmtick(, labsize(small)) title(Square Neighbor h1 h2 
> CV, size(small) margin(small)) legend(size(small) margin(zero) region(margin(tiny)) bmargin(small))

. graph save  scv2, replace
(note: file scv2.gph not found)
(file scv2.gph saved)

. 
. twoway (scatter s2_rep s1_rep, msymbol(smcircle_hollow)) (scatter s2_rep s1_rep if q_l_ocv==1, msymbol(smcircle)), ytitle(, size(small)) ylabel(-0.5(0.1)0.5
> , labsize(small)) ymtick(, labsize(small)) xtitle(, size(small)) xlabel(-0.5(0.1)0.5, labsize(small)) xmtick(, labsize(small))  title(Oval Neighbor h CV, si
> ze(small) margin(small)) legend(size(small) margin(zero) region(margin(tiny)) bmargin(small))

. graph save  ocv, replace
(note: file ocv.gph not found)
(file ocv.gph saved)

. 
. twoway (scatter s2_rep s1_rep, msymbol(smcircle_hollow)) (scatter s2_rep s1_rep if q_l_ocv2==1, msymbol(smcircle)), ytitle(, size(small)) ylabel(-0.5(0.1)0.
> 5, labsize(small)) ymtick(, labsize(small)) xtitle(, size(small))  xlabel(-0.5(0.1)0.5, labsize(small)) xmtick(, labsize(small))  title(Oval Neighbor h1 h2 
> CV, size(small) margin(small)) legend(size(small) margin(zero) region(margin(tiny)) bmargin(small))

. graph save  ocv2, replace
(note: file ocv2.gph not found)
(file ocv2.gph saved)

. 
. graph combine scv.gph  scv2.gph  ocv.gph  ocv2.gph, ycommon xcommon imargin(vsmall) xsize(9) ysize(8) graphregion(margin(small))

. graph save Figure3,replace
(note: file Figure3.gph not found)
(file Figure3.gph saved)

. 
. 
. 
. 
. 
. ************************ Table 2 Y=LPI ****************************
. ************************ Results of Beta_d ************************
. ********** OLS results **********************************
. estimates table y_l_1_srt y_l_1_scv y_l_1_scv2 y_l_1_ort y_l_1_ocv y_l_1_ocv2 , t keep(d)

--------------------------------------------------------------------------------------------
    Variable | y_l_1_srt    y_l_1_scv    y_l_1_scv2   y_l_1_ort    y_l_1_ocv    y_l_1_ocv2  
-------------+------------------------------------------------------------------------------
           d |  1.3853408    .61991334    .65500748    .94457713    .44711081    .48045348  
             |       3.98         1.91         1.73         2.19         1.57         1.60  
--------------------------------------------------------------------------------------------
                                                                                 legend: b/t

. ********** Bound-Wei. results (CI is calculated by bootstrap)
. disp bwei_l_scv bwei_l_scv2 bwei_l_ocv bwei_l_ocv2
-.0522909-.01362946.16079761-.23815796

. ********** Min.SRD results ******************************
. estimates table  y_l_m_srt y_l_m_scv y_l_m_scv2, t keep(d)

-----------------------------------------------------
    Variable | y_l_m_srt    y_l_m_scv    y_l_m_scv2  
-------------+---------------------------------------
           d |  .08037004    .05920689    .00610998  
             |       0.36         0.28         0.03  
-----------------------------------------------------
                                          legend: b/t

. ********** RD1.SRD results ******************************
. estimates table  y_l_11_srt y_l_11_scv y_l_11_scv2, t keep(d)

-----------------------------------------------------
    Variable | y_l_11_srt   y_l_11_scv   y_l_11_s~2  
-------------+---------------------------------------
           d |  .44801069    .27187587    .12772666  
             |       0.94         0.68         0.27  
-----------------------------------------------------
                                          legend: b/t

. ********** RD2.SRD results ******************************
. estimates table  y_l_12_srt y_l_12_scv y_l_12_scv2, t keep(d)

-----------------------------------------------------
    Variable | y_l_12_srt   y_l_12_scv   y_l_12_s~2  
-------------+---------------------------------------
           d |  .11420197    .12829448    .14017263  
             |       0.44         0.52         0.61  
-----------------------------------------------------
                                          legend: b/t

. 
. 
. ************************ Results of Beta_1/2 **********************
. ********** Square neighbor h RoT **********************************
. estimates table y_l_1_srt y_l_1_scv y_l_1_scv2 y_l_1_ort y_l_1_ocv y_l_1_ocv2, t keep(d1 d2)

--------------------------------------------------------------------------------------------
    Variable | y_l_1_srt    y_l_1_scv    y_l_1_scv2   y_l_1_ort    y_l_1_ocv    y_l_1_ocv2  
-------------+------------------------------------------------------------------------------
          d1 | -.58420758   -.38156882    -.5708109   -.84975449   -.55130752   -.63052392  
             |      -2.35        -1.00        -1.63        -2.10        -1.80        -1.87  
          d2 | -.62666607    -.3823244   -.46235185   -.71939809   -.37842453   -.37524485  
             |      -1.79        -1.49        -1.91        -2.36        -2.23        -1.94  
--------------------------------------------------------------------------------------------
                                                                                 legend: b/t

. 
. 
. 
. 
. 
. ************************ Table 3 Y=MLI ****************************
. ************************ Results of Beta_d ************************
. ********** OLS results **********************************
. estimates table y_m_1_srt y_m_1_scv y_m_1_scv2 y_m_1_ort y_m_1_ocv y_m_1_ocv2 , t keep(d)

--------------------------------------------------------------------------------------------
    Variable | y_m_1_srt    y_m_1_scv    y_m_1_scv2   y_m_1_ort    y_m_1_ocv    y_m_1_ocv2  
-------------+------------------------------------------------------------------------------
           d |  .62933474    .49720755    .36119923    .66559514    .26821461    .26436105  
             |       1.48         1.34         0.99         1.46         0.70         0.68  
--------------------------------------------------------------------------------------------
                                                                                 legend: b/t

. ********** Bound-Wei. results (CI is calculated by bootstrap)
. disp bwei_m_scv bwei_m_scv2 bwei_m_ocv bwei_m_ocv2
-.01106047-.12746368-.10847784-.16824643

. ********** Min.SRD results ******************************
. estimates table  y_m_m_srt y_m_m_scv y_m_m_scv2, t keep(d)

-----------------------------------------------------
    Variable | y_m_m_srt    y_m_m_scv    y_m_m_scv2  
-------------+---------------------------------------
           d |  .19747542    .24176189    .24176189  
             |       1.13         1.35         1.35  
-----------------------------------------------------
                                          legend: b/t

. ********** RD1.SRD results ******************************
. estimates table  y_m_11_srt y_m_11_scv y_m_11_scv2, t keep(d)

-----------------------------------------------------
    Variable | y_m_11_srt   y_m_11_scv   y_m_11_s~2  
-------------+---------------------------------------
           d |  .49924344    .26063426   -.22895173  
             |       1.38         0.84        -0.92  
-----------------------------------------------------
                                          legend: b/t

. ********** RD2.SRD results ******************************
. estimates table  y_m_12_srt y_m_12_scv y_m_12_scv2, t keep(d)

-----------------------------------------------------
    Variable | y_m_12_srt   y_m_12_scv   y_m_12_s~2  
-------------+---------------------------------------
           d |   .1215923    .14875721    .14875721  
             |       0.50         0.63         0.63  
-----------------------------------------------------
                                          legend: b/t

. 
. 
. ************************ Results of Beta_1/2 **********************
. ********** Square neighbor h RoT **********************************
. estimates table y_m_1_srt y_m_1_scv y_m_1_scv2 y_m_1_ort y_m_1_ocv y_m_1_ocv2, t keep(d1 d2)

--------------------------------------------------------------------------------------------
    Variable | y_m_1_srt    y_m_1_scv    y_m_1_scv2   y_m_1_ort    y_m_1_ocv    y_m_1_ocv2  
-------------+------------------------------------------------------------------------------
          d1 |  .35134681     .2215773   -.14340786    .03198609   -.14581949   -.08825597  
             |       0.95         0.54        -0.38         0.08        -0.38        -0.22  
          d2 |  -.4123523   -.36561847   -.31883649   -.62650523   -.37203105   -.38410066  
             |      -1.41        -1.60        -1.26        -2.98        -1.58        -1.54  
--------------------------------------------------------------------------------------------
                                                                                 legend: b/t

. 
. 
. 
. log off
      name:  <unnamed>
       log:  c:\dataverse_files\Election_26AUG2017_Stata.log
  log type:  text
 paused on:  10 Mar 2018, 10:03:44
--------------------------------------------------------------------------------------------------------------------------------------------------------------
